package com.mezz.bones.im.logic.repository.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mezz.bones.im.logic.mapper.IChatUserMapper;
import com.mezz.bones.im.logic.domain.entity.ChatUser;
import com.mezz.bones.im.logic.repository.IChatUserRepository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mezz
 * @since 2024-12-20
 */
@Service
public class ChatUserRepositoryImpl extends ServiceImpl<IChatUserMapper, ChatUser> implements IChatUserRepository {

    @Override
    public ChatUser getByUserId(String userId) {

        LambdaQueryWrapper<ChatUser> q = new LambdaQueryWrapper<>();
        q.eq(ChatUser::getUserId,userId);
        return getOne(q);
    }
    @Override
    public List<ChatUser> getByUserIds(Collection<String> userIds) {

        if(CollUtil.isEmpty(userIds)){
            return new ArrayList<>();
        }

        LambdaQueryWrapper<ChatUser> q = new LambdaQueryWrapper<>();
        q.in(ChatUser::getUserId,userIds);
        return list(q);
    }

    @Override
    public void removeByUserId(String userId) {

        LambdaUpdateWrapper<ChatUser> del = new LambdaUpdateWrapper<>();
        del.eq(ChatUser::getUserId,userId);
        del.set(ChatUser::getUpdateTime,new Date());
        del.set(ChatUser::getIsDel,1);
        this.update(del);
    }
}
